package com.lyw.ioc.service;

import com.lyw.ioc.model.Student;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired//类型注入
    private Student s5;

    @Qualifier("s2")//指定bean名称但是要加@Autowired
    @Autowired
    private Student s6;

    @Resource(name = "s4")//指定bean名称 名称注入
    private Student s7;

    @Autowired//虽然通过类型注入, 当一个类型有多个对象时, 会根据变量名进行注入, 如果痘毒不上, 会报错
    private Student s1;


    public void print() {
        System.out.println("Hello Service");
        System.out.println(s5);
        System.out.println(s6);
        System.out.println(s7);

        System.out.println(s1);
    }

}
